package com.initialize.core.security.handler;


import cn.hutool.json.JSONObject;
import com.initialize.core.security.service.UserService;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/1/5
 * Time: 4:55 下午
 *
 * @Description: 登录成功处理逻辑
 */
@Component
public class BaseAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    final
    UserService userService;

    public BaseAuthenticationSuccessHandler(UserService userService) {
        this.userService = userService;
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 1004);
        jsonObject.put("msg", "登录成功");

        httpServletResponse.setContentType("application/json;charset=UTF-8");
        httpServletResponse.getWriter().print(jsonObject.toString());
    }
}